#include "Particle.h"


Particle::Particle(void)
{
	r = g = b = alpha = size =  1.0;
	lifetime = 10*60;//10 seconds * 60fps = actual number of frames
	position = *(new Vector(1,1,0));
	velocity = *(new Vector(1,1,0));
	acceleration = *(new Vector(0,-0.01,0));
	alpha_fadeIncr = alpha/lifetime;
}

Particle::Particle(float _r, float _g, float _b, float _alpha, float pointSize, Vector position, Vector initialVelocity, Vector acceleration, float lifetime_Seconds, int frameRate)
{
	r = _r;
	g = _g;
	b = _b;
	alpha = _alpha;
	size = pointSize;
	this->position = position;
	velocity = initialVelocity;
	this->acceleration = acceleration;
	lifetime = lifetime_Seconds * frameRate;
	alpha_fadeIncr =  alpha/lifetime;
}

void Particle::update()
{
	lifetime--;
	position.addVector(velocity);
	position.addVector(acceleration);
	velocity.addVector(acceleration);
}

void Particle::draw()
{
	update();
	glColor4f(r,g,b,alpha);
	glPointSize(size);
	glBegin(GL_POINTS);
		glVertex3f(this->position.thisVector.x,this->position.thisVector.y, this->position.thisVector.z);
	glEnd();
	alpha -= alpha_fadeIncr;
	
}

void Particle::setColor(float _r, float _g, float _b, float _alpha)
{
	r = _r;
	g = _g;
	b = _b;
	alpha = _alpha;
}

void Particle::setVelocity(Vector *newVelocity)
{
	velocity = *newVelocity;
}

void Particle::setAcceleration(Vector *newAcceleration)
{
	acceleration = *newAcceleration;
}

Particle::~Particle(void)
{
}
